//
//  Boutique_classify_Cell.m
//  Food
//
//  Created by dllo on 15/7/15.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "Boutique_classify_Cell.h"
#import "UIImageView+WebCache.h"
#import "BaseHeader.h"
@implementation Boutique_classify_Cell

-(void)dealloc
{
    [_imageView release];
    [_titleView release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageView];
        
        self.titleView = [[UILabel alloc] init];
        [self.titleView setTextAlignment:NSTextAlignmentCenter];
        [self.titleView setFont:[UIFont systemFontOfSize:15]];
        [self.contentView addSubview:self.titleView];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
//    self.imageView.frame = CGRectMake(10, 10, layoutAttributes.frame, 100);
    self.imageView.frame = layoutAttributes.bounds;
    [self.imageView.layer setCornerRadius:self.imageView.frame.size.width / 2.0];
    self.imageView.center = CGPointMake(layoutAttributes.frame.size.width / 2.0, (self.imageView.frame.size.height + self.imageView.frame.origin.y) / 2.0);
    self.titleView.frame = CGRectMake(0, 0.8 *layoutAttributes.frame.size.height, layoutAttributes.frame.size.width, 20);
}

- (void)setModel:(BoutiqueModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }

    [self.imageView sd_setImageWithURL:[NSURL URLWithString:model.imageFilename]];
    self.titleView.text = model.name;
}

@end
